package cn.pomelo.secondskill.service.impl;

import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import cn.pomelo.secondskill.model.Address;
import cn.pomelo.secondskill.mapper.AddressMapper;
import cn.pomelo.secondskill.service.AddressService;

import java.util.List;

@Service
public class AddressServiceImpl implements AddressService{

    @Resource
    private AddressMapper addressMapper;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return addressMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Address record) {
        return addressMapper.insert(record);
    }

    @Override
    public int insertSelective(Address record) {
        return addressMapper.insertSelective(record);
    }

    @Override
    public Address selectByPrimaryKey(Integer id) {
        return addressMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(Address record) {
        return addressMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Address record) {
        return addressMapper.updateByPrimaryKey(record);
    }

    @Override
    public List<Address> findByUserid(Integer userid) {
        return addressMapper.selectByUserid(userid);
    }

    @Override
    public void updateDefaultAdd() {
        addressMapper.updateDefaultAdd();
    }

    @Override
    public Address findDefaultAddByUserid(Integer userid) {
        List<Address> list = findByUserid(userid);
        for (Address add : list) {
            if (add.getDefaultAdd()) {
                return add;
            }
        }
        return null;
    }

}
